/*
 *  copy source from lua-5.1.4 to learn lua implementation
 */

#ifndef lua_h
#define lua_h

#include <stdarg.h>
#include <stddef.h>

#include "luaconf.h"

#define LUA_VERSION "Lua 5.1"
#define LUA_RELEASE "Lua 5.1.4"
#define LUA_VERSION_NUM 501
#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
#define LUA_AUTHORS   "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"

#define LUA_REGISTRYINDEX (-10000)
#define LUA_ENVIRONINDEX  (-10001)
#define LUA_GLOBALSINDEX  (-10002)
#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))

typedef struct lua_State lua_State;

typedef int (*lua_CFunction) (lua_State *L);

typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);

typedef struct lua_Debug lua_Debug;  /* activation record */

typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);

#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER  double

typedef LUA_NUMBER lua_Number;

#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)

#define lua_open()  luaL_newstate()

/*
** basic types
*/
#define LUA_TNONE		(-1)

#define LUA_TNIL		0
#define LUA_TBOOLEAN		1
#define LUA_TLIGHTUSERDATA	2
#define LUA_TNUMBER		3
#define LUA_TSTRING		4
#define LUA_TTABLE		5
#define LUA_TFUNCTION		6
#define LUA_TUSERDATA		7
#define LUA_TTHREAD		8

#define LUA_MINSTACK	20

struct lua_Debug {
  int event;
  const char *name; /* (n) */
  const char *namewhat; /* (n) `global', `local', `field', `method' */
  const char *what; /* (S) `Lua', `C', `main', `tail' */
  const char *source; /* (S) */
  int currentline;  /* (l) */
  int nups;   /* (u) number of upvalues */
  int linedefined;  /* (S) */
  int lastlinedefined;  /* (S) */
  char short_src[LUA_IDSIZE]; /* (S) */
  /* private part */
  int i_ci;  /* active function */
};

typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);

typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);

#endif
